<template>
  <el-drawer v-model="dialogVisible"
             title="修改时间"
             size="50%"
             :close-on-click-modal="false"
             :destroy-on-close="destroyOnClose">
    <div class="formDrawer">
      <div class="body">
        <el-form :model="form" ref="formRef" :rules="rules" label-width="80px" :inline="false">
          <el-form-item label="任务id" prop="jobName">
            <el-input v-model="form.jobName" disabled
                      style="width:70%;"/>
          </el-form-item>
          <el-form-item label="任务组名" prop="jobGroupName">
            <el-input v-model="form.jobGroupName" disabled
                      style="width:70%;"/>
          </el-form-item>
          <el-form-item label="任务时间" prop="jobTime">
            <el-input v-model="form.jobTime" placeholder="请输入cron表达式,例如:'* * * * * ?'"
                      style="width:70%;"/>
          </el-form-item>
        </el-form>
      </div>
      <div class="actions">
        <el-button type="primary" @click="submit" :loading="loading">{{ confirmText }}</el-button>
        <el-button type="default" @click="close">取消</el-button>
      </div>
    </div>
  </el-drawer>
</template>
<script setup>
import {ref, reactive} from "vue"
import {getAllWorkData, updateWorkTimeData} from "~/api/task"
// import * as mock_data from './mockdata'
import {toast} from "~/composables/util";

const dialogVisible = ref(false)
const props = defineProps({

  destroyOnClose: {
    type: Boolean,
    default: false
  }
  ,
  confirmText: {
    type: String,
    default: "提交"
  },
})
const form = reactive({
  jobName: "",
  jobGroupName: "",
  jobTime: "" // cron表达式
})

const jobName = ref(0)
const open = (row) => {
  form.jobName = row.jobName
  form.jobGroupName = row.jobGroup
  console.log('update,row', row)
  // row.bannersLoading = true
  // getAllWorkData(mock_data.Mock_jobQuery).then(res => {
  dialogVisible.value = true
  // })
  //   .finally(() => {
  //   })
}
const emit = defineEmits(["reloadData"])
const loading = ref(false)
const submit = () => {
  loading.value = true
  let _combine = {
    jobName: form.jobName,
    jobGroupName: form.jobGroupName,
    jobTime: form.jobTime
  }
  updateWorkTimeData(_combine).then(res => {
    console.log(res);
    toast("修改时间成功")
    dialogVisible.value = false
    emit("reloadData")
  })
    .finally(() => {
      loading.value = false
    })
}

defineExpose({
  open
})
</script>
